<template>
  <view>
    <view class="form_active_title_2">最近一份工作经历</view>
    <u-field
	placeholder-style="color:#757575;font-size:14px !important;" 
      required
      v-model="work.companyname"
      label="公司名称"
      placeholder="请输入公司名称"
      class="reset_after"
    />
    <u-field
	placeholder-style="color:#757575;font-size:14px !important;" 
      required
      v-model="work.jobname"
      label="职位名称"
      placeholder="请输入职位名称"
      class="reset_after"
    />
    <u-field
	placeholder-style="color:#757575;font-size:14px !important;" 
      required
	  disabled
      :value="work.starttime"
      label="入职时间"
      placeholder="点击选择入职时间"
      @click="showPickerStartDate = true"
      class="form_choose reset_after"
    />
	<!-- v-model="currentStartDate" -->
	<!-- :min-date="minDate"
        :max-date="maxDate" -->
      <u-picker
	    :params="dateParams"
		v-model="showPickerStartDate"
        mode="time"
        title="选择入职时间"
        @confirm="onConfirmStartDate"
        @cancel="showPickerStartDate = false"
      />
    <u-field
	placeholder-style="color:#757575;font-size:14px !important;" 
      required
	  disabled
      :value="work.endtimeName"
      label="离职时间"
      placeholder="点击选择离职时间"
      @click="showPickerEndDate = true"
      class="form_choose reset_after"
    />
    <!-- <u-popup v-model="showPickerEndDate" :mask="false" mode="bottom"> -->
      <!-- <view class="for-pop-title" @click="handleWorkEndTime">至今</view> -->
	  <!-- v-model="currentEndDate" -->
	  <!-- :min-date="minDate"
        :max-date="maxDate" -->
      <u-picker
	    :params="dateParams"
        v-model="showPickerEndDate"
        mode="time"
        title=" "
        @confirm="onConfirmEndDate"
        @cancel="showPickerEndDate = false"
      />
    <!-- </u-popup> -->
    <u-field
	placeholder-style="color:#757575;font-size:14px !important;" 
      required
      v-model="work.duty"
      rows="3"
      type="textarea"
      label="工作职责"
      placeholder="简单描述一下你的工作职责"
      show-word-limi
      class="reset_after no_border"
    />
    <view v-if="isShowAddEduBox">
      <view class="form_active_title_2 mt_9">教育经历 <text class="title_close" @click="isShowAddEduBox = !isShowAddEduBox"></text></view>
      <u-field
	  placeholder-style="color:#757575;font-size:14px !important;" 
      required
        v-model="education.school"
        label="学校名称"
        placeholder="请填写"
        class="reset_after"
      />
      <u-field
	  placeholder-style="color:#757575;font-size:14px !important;" 
      required
        v-model="education.major"
        label="专业名称"
        placeholder="请填写"
        class="reset_after"
      />
      <u-field
	  placeholder-style="color:#757575;font-size:14px !important;" 
		disabled
        required
        :value="education.educationName"
        label="取得学历"
        placeholder="请选择"
        @click="showPickerEdu = !showPickerEdu"
        class="form_choose reset_after"
      />
        <u-picker
		  v-model="showPickerEdu"
		  mode="selector"
		  :range="columnsEdu"
		  range-key="text"
          @confirm="onConfirmEducation"
          @cancel="showPickerEdu = false"
        />
      <u-field
	  placeholder-style="color:#757575;font-size:14px !important;" 
	    disabled
        required
        :value="education.starttime"
        label="入学时间"
        placeholder="请选择"
        @click="showPickerEduStartDate = true"
        class="form_choose reset_after"
      />
	  <!-- v-model="currentStartDate" -->
	  <!-- :min-date="minDate"
	  :max-date="maxDate" -->
      <u-picker
		v-model="showPickerEduStartDate"
		:params="dateParams"
        mode="time"
        title="选择入学时间"
        @confirm="onConfirmEduStartDate"
        @cancel="showPickerEduStartDate = false"
      />
      <u-field
	  placeholder-style="color:#757575;font-size:14px !important;" 
        required
		disabled
        :value="education.endtimeName"
        label="毕业时间"
        placeholder="请选择"
        @click="showPickerEduEndDate = true"
        class="form_choose reset_after"
      />
        <!-- <view class="for-pop-title" @click="handleEduEndTime">至今</view> -->
		<!-- v-model="currentEndDate" -->
		<!-- :min-date="minDate"
          :max-date="maxDate" -->
        <u-picker
		  :params="dateParams"
		  v-model="showPickerEduEndDate" 
          mode="time"
          title=" "
          @confirm="onConfirmEduEndDate"
          @cancel="showPickerEduEndDate = false"
        />
    </view>
    <view v-if="!isShowAddEduBox">
      <view class="form_split_18"></view>
      <view class="add_handle_bar" @click="isShowAddEduBox = !isShowAddEduBox">
        <view class="add_handle">添加教育经历</view>
      </view>
    </view>
    <view class="form_split_18"></view>
    <view style="margin: 16px; position: relative">
      <u-button shape="circle" type="primary" @click="handleSubmit">
        完成
      </u-button>
    </view>
	<u-top-tips ref="uTips"></u-top-tips>
  </view>
</template>

<script>
import http from '@/utils/http'
import api from '@/api'
export default {
  name: 'RegIntStep4',
  created () {
    this.$store.dispatch('getClassify', 'education')
    this.initDate()
  },
  computed: {
    columnsEdu () {
      return this.$store.state.classifyEdu
    }
  },
  data () {
    return {
	  dateParams:{
		year: true,
		month: true,
		day: false,
		hour: false,
		minute: false,
		second: false
	  },
      showPickerEduStartDate: false,
      showPickerEduEndDate: false,
      currentStartDate: '',
      currentEndDate: '',
      showPickerStartDate: false,
      showPickerEndDate: false,
      isShowAddEduBox: false,
      showPickerEdu: false,
      minDate: '',
      maxDate: '',
      'work': {
        'companyname': '',
        'jobname': '',
        'starttime': '',
        'endtime': '',
        'endtimeName': '',
        'todate': 0,
        'duty': ''
      },
      'education': {
        'school': '',
        'major': '',
        'starttime': '',
        'endtime': '',
        'endtimeName': '',
        'todate': 0,
        'education': '',
        'educationName': ''
      }
    }
  },
  methods: {
    // 设置日期插件默认值
    initDate () {
      let nowDate = new Date()
      let nowYear = nowDate.getFullYear()
      let minYear = nowYear - 59
      this.minDate = new Date(minYear, 0)
      this.maxDate = nowDate
      this.currentStartDate = nowDate
      this.currentEndDate = nowDate
    },
	// 取得学历
    onConfirmEducation (value) {
      this.education.education = this.columnsEdu[value].id
      this.education.educationName = this.columnsEdu[value].text
      this.showPickerEdu = !this.showPickerEdu
    },
    handleWorkEndTime () {
      this.work.endtime = ''
      this.work.endtimeName = '至今'
      this.work.todate = 1
      this.showPickerEndDate = !this.showPickerEndDate
    },
    handleEduEndTime () {
      this.education.endtime = ''
      this.education.endtimeName = '至今'
      this.education.todate = 1
      this.showPickerEduEndDate = !this.showPickerEduEndDate
    },
	// 离职时间
    onConfirmEndDate (value) {
	  let {year,month} = value
      this.work.endtime = year + '-' + month
      this.work.endtimeName = year + '-' + month
      this.work.todate = 0
      this.showPickerEndDate = !this.showPickerEndDate
    },
	// 毕业时间
    onConfirmEduEndDate (value) {
	  let {year,month} = value
      this.education.endtime = year + '-' + month
      this.education.endtimeName = year + '-' + month
      this.education.todate = 0
      this.showPickerEduEndDate = !this.showPickerEduEndDate
    },
	// 入职时间
    onConfirmStartDate (value) {
	  let {year,month} = value
      this.work.starttime = year + '-' + month
      this.showPickerStartDate = !this.showPickerStartDate
    },
	// 入学时间
    onConfirmEduStartDate (value) {
	  let {year,month} = value
      this.education.starttime = year + '-' + month
      this.showPickerEduStartDate = !this.showPickerEduStartDate
    },
    dateFormat (time) {
      let year = time.getFullYear()
      let month = time.getMonth() + 1
      return `${year}-${month}`
    },
    handleSubmit () {
      if (!this.work.companyname) {
		this.$refs.uTips.show({
			title: '请填写公司名称',
			type: 'error'
		})
        return false
      }
      if (!this.work.jobname) {
		this.$refs.uTips.show({
			title: '请填写职位名称',
			type: 'error'
		})
        return false
      }
      if (!this.work.starttime) {
		this.$refs.uTips.show({
			title: '请选择入职时间',
			type: 'error'
		})
        return false
      }
      if (!this.work.duty) {
		this.$refs.uTips.show({
			title: '请填写工作职责',
			type: 'error'
		})
        return false
      }
      if (!this.work.endtime) {
        this.work.todate = 1
      }
      let postData = {
        'work': {
          'companyname': this.work.companyname,
          'jobname': this.work.jobname,
          'starttime': this.work.starttime,
          'endtime': this.work.endtime,
          'todate': this.work.todate,
          'duty': this.work.duty
        }
      }
      if (this.isShowAddEduBox) {
        if (!this.education.school) {
		  this.$refs.uTips.show({
		  	title: '请填写学校名称',
		  	type: 'error'
		  })
          return false
        }
        if (!this.education.major) {
		  this.$refs.uTips.show({
		  	title: '请选择专业名称',
		  	type: 'error'
		  })
          return false
        }
        if (!this.education.education) {
		  this.$refs.uTips.show({
		  	title: '请选择取得学历',
		  	type: 'error'
		  })
          return false
        }
        if (!this.education.starttime) {
		  this.$refs.uTips.show({
		  	title: '请选择入学时间',
		  	type: 'error'
		  })
          return false
        }
        if (!this.education.endtime) {
          this.education.todate = 1
        }
        postData.education = {
          'school': this.education.school,
          'major': this.education.major,
          'starttime': this.education.starttime,
          'endtime': this.education.endtime,
          'todate': this.education.todate,
          'education': this.education.education
        }
      }

      http.post(api.reg_resume_int_step4, postData)
        .then(res => {
          uni.navigateTo({
          	url:'/personal/AddResumeFinish'
          })
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.add_handle_bar .add_handle {
  display: inline-block; 
  font-size: 28rpx; 
  color: #333333; 
  padding-left: 46rpx; 
  vertical-align: middle;
  background-image:url(../static/img/add_handle.png); 
  background-position: 0 center;
  background-repeat: no-repeat;
  background-size: 40rpx; 
}
</style>
